The ControllerBase
class contains all the necessary functionality to handle API
requests and responses. The Controller
class inherits from ControllerBase
and adds support for Views, PartialViews and ViewComponents.
Inheriting from Controller
when not using any View-specific functionality exposes unnecessary methods and can lead to confusion about
the intention of the class.
Furthermore, inheriting from Controller
may come with a performance cost. Even though the controller might only deal with API
operations, the support for Views might introduce some overhead from the MVC framework during the request processing pipeline.
An issue is raised when:
- The class is marked with the
[ApiController]
attribute.
- The class inherits directly from
Controller
.
- No View-specific functionality is used in the class.
Exceptions